package view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.util.List;

import javax.swing.JLabel;
import javax.swing.JPanel;

import controller.Controller;
import controller.ControllerLighter;

import view.items.PanelPendingCall;
import view.items.PanelTitre;

import model.Call;
import model.EnumCallStatus;
import model.Model;

public class ViewPendingCall extends ViewAbstract {

	private Model model;
	private Controller controller;
	private ControllerLighter controllerLighter;

	public ViewPendingCall(Controller controller,ControllerLighter controllerLighter, int x, int y, int width, int height) {
		this.model=controller.getModel();
		this.controller=controller;
		this.controllerLighter=controllerLighter;
		this.setBackground(Color.LIGHT_GRAY);
		this.setBounds(x,y,width,height);
		this.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 1));
		this.refresh();
	}

	public void refresh() {
		//System.out.println("refreshViewPendingCall");
		this.removeAll();
		//Partie statique
		PanelTitre titre = new PanelTitre("Pending Call");
		this.add(titre);
		//Partie dynamique
				List<Call> pendingCall = this.model.getCall(EnumCallStatus.PENDING);
				if(pendingCall.size()!=0){
				for (Call call : pendingCall) {
					PanelPendingCall panelPendingCall = new PanelPendingCall(call,controller, controllerLighter);
					this.add(panelPendingCall);
				}}
				else{
					JLabel label;
					label = new JLabel("No pending call");
					this.add(label);
				}
				this.repaint();
				this.revalidate();
	}
}
